package inabit.data;
/**An inabit method is a method that can be called during the inference at the
 * consequent expression of a fired rule. The InabitMethod can be referred as part
 * of an arithmetic expression by the <i>MethodExpression</i>
 * @see inabit.data.expression.arithmetic.MethodExpression
 * @author Rafael Rocha*/
public abstract class InabitMethod {
	private String id;
	private int numParams;
	/**Specifies the id by which the method can be called at an arithmetic expression*/
	public InabitMethod(String id) {
		this(id, -1);
	}
	/**Besides the method id this constructor also specifies a fixed number of parameters to this method*/
	public InabitMethod(String id, int numParams) {
		this.id = id;
		this.numParams = numParams;
	}
	/**Returns this method's id*/
	public String getName() {
		return id;
	}
	/**Evaluate if the number of parameters is valid then execute the <i>getResult</i> method*/
	public String evaluate(String... params) throws Exception{
		if(numParams >= 0 && numParams != params.length) {
			throw new Exception("method " + id + " must have " + numParams + " parameters");
		}
		return getResult(params);
	}
	/**Executes this method over the specified parameters and returns a string representing the result*/
	protected abstract String getResult(String... params);
}
